from rest_framework import serializers
from cars.models import Car
from cars.serializers import CarLstSerl
from persons.serializers import PersonBriefSerl
from teacher.models import (
    TeacherCar,
    TeacherInvite,
    TeacherInviteCar,
    TeacherInvitePerson,
    TeacherInviteVerify,
    TeacherModel,
    TeacherPerson,
)


class TeacherSerl(serializers.ModelSerializer):
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = TeacherModel
        exclude = ("created",)



class TeacherBriefSerl(serializers.ModelSerializer):

    class Meta:
        model = TeacherModel
        fields = (
            "id",
            "dept",
            "name",
            "phone",
        )

class TeacherBriefNoPhoneSerl(serializers.ModelSerializer):

    class Meta:
        model = TeacherModel
        fields = (
            "id",
            "dept",
            "name",
        )

class TeacherPersonSerl(serializers.ModelSerializer):
    teacher = TeacherBriefSerl()
    person = PersonBriefSerl()

    class Meta:
        model = TeacherPerson
        fields = ("id", "teacher", "person")


class TeacherCarSerl(serializers.ModelSerializer):
    teacher = TeacherBriefSerl()
    car = CarLstSerl()

    class Meta:
        model = TeacherCar
        fields = ("id", "teacher", "car")


class TeacherInviteDetSerl(serializers.ModelSerializer):
    teacher = TeacherBriefSerl()
    STATUS_CHOISE = (
        (0, "被访者审核中"),
        (1, "上级审核中"),
        (2, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )
    when = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = TeacherInvite
        exclude = ("created",)


class TeacherInviteLstSerl(serializers.ModelSerializer):
    teacher = TeacherBriefSerl()
    
    STATUS_CHOISE = (
        (0, "被访者审核中"),
        (1, "上级审核中"),
        (2, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )
    when = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = TeacherInvite
        fields = ("id", "teacher", "status", "status_text", "when")


class TeacherInvitePersonSerl(serializers.ModelSerializer):
    invite = TeacherInviteLstSerl()
    person = PersonBriefSerl()

    class Meta:
        model = TeacherInvitePerson
        fields = ("id", "invite", "person")


class TeacherInviteCarSerl(serializers.ModelSerializer):

    invite = TeacherInviteLstSerl()
    car = CarLstSerl()

    class Meta:
        model = TeacherInviteCar
        fields = ("id", "invite", "car")


class TeacherInviteVerifySerl(serializers.ModelSerializer):
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
    teacher = TeacherBriefSerl()
    STATGE_CHOISE = (
        (0, "被访者审核中"),
        (1, "上级审核中"),
        (2, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
    )
    stage_text = serializers.ChoiceField(
        choices=STATGE_CHOISE, source="get_stage_display"
    )
    STATUS_CHOISE = (
        (0, "待审核"),
        (1, "审核通过"),
        (2, "审核失败"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )

    class Meta:
        model = TeacherInviteVerify
        exclude = ("created",)
